package cn.concete;

import cn.Config;
import cn.WorkType;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/****
 * 销售人员， 基础工资为每月3000，
 * 每月基础销售额应为20000，
 * 如果销售额为20000-30000，则超出部分（超出20000部分）提成率为5%，
 * 如果销售额为30000及以上，则超出部分（超出20000部分）提成率为8%。
 *
 * */
public class SaleWorkTypeConcrete implements WorkType {

    private BigDecimal amount = null;

    private BigDecimal saleBaseMoney = Config.saleBaseMoney;

    private String birthday = null;

    public SaleWorkTypeConcrete(String amount, String birthday) {

        this.amount = new BigDecimal(amount);
        this.birthday = birthday;
    }

    @Override
    public BigDecimal calc() {

        BigDecimal baseMoney = new BigDecimal("0");
        if (checkToday(this.birthday)) {
            System.out.println("该员工生日,工资额外加：" + Config.birthDayMonty.toString());
            baseMoney = baseMoney.add(Config.birthDayMonty);
        }


        //使用动态规划进行步骤分解
        //如果超出30000
        //直接计算 20000-30000需要支付提成, 然后计算超出30000 ,部分工资
        if ((this.amount.compareTo(new BigDecimal("30000")) == 1)) {
            saleBaseMoney = saleBaseMoney.add(
                    this.amount.subtract(new BigDecimal("30000")).
                            multiply(new BigDecimal(Config.sale_30000_Rate)));
            return saleBaseMoney.add(new BigDecimal("10000").multiply(new BigDecimal(Config.sale_20000_Rate)));
        }
        //大于 20000
        if ((this.amount.compareTo(new BigDecimal("20000")) == 1)) {
            saleBaseMoney = saleBaseMoney.add(this.amount.subtract(new BigDecimal("20000")).multiply(new BigDecimal(Config.sale_20000_Rate)));
        }
        return saleBaseMoney;
    }

    public static void main(String[] args) {

        String birthDay = "2020-08--11";
        if (StringUtils.isBlank(birthDay)) {

        }
        String eL = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
        Pattern p = Pattern.compile(eL);
        Matcher m = p.matcher(birthDay);
        boolean dateFlag = m.matches();
        if (!dateFlag) {
            System.out.println("请修正员工生日格式为：yyyy-mm-dd");
            return;
        }
        String monthDay = sd.format(new Date()).toString();
        birthDay = birthDay.substring(birthDay.indexOf("-")+1, birthDay.length());
        if(monthDay.equals(birthDay)){
            System.out.println("今天是生日");
        }else {
            System.out.println("不是");
        }


    }
}
